package dtm

import (
	"gitee.com/xuyiping_admin/pkg/xerr"
	"kpt-dtm/model"
)

func (s *StoreEntry) GetYConfig(pastureId int64) (*model.YConfig, error) {
	yConfig := &model.YConfig{}
	if err := s.DB.Model(new(model.YConfig)).
		Where("pasture_id = ?", pastureId).
		Where("is_show = ?", model.IsShowOK).
		First(yConfig).Error; err != nil {
		return nil, xerr.WithStack(err)
	}
	return yConfig, nil
}

func (s *StoreEntry) GetYMqtt(pastureId int64) (*model.YMqtt, error) {
	yMqtt := &model.YMqtt{}
	if err := s.DB.Model(new(model.YMqtt)).
		Where("pasture_id = ?", pastureId).
		First(yMqtt).Error; err != nil {
		return nil, xerr.WithStack(err)
	}
	return yMqtt, nil
}
